package hot100.logos1To10;

import java.util.HashSet;
import java.util.Set;

/**
 * @author logos
 * date 2025/7/9 11:42
 * @version v1.0
 * @Package hot100
 */
public class logos3 {


    /**
     * 3.最长连续序列
     * https://leetcode.cn/problems/longest-consecutive-sequence/?envType=study-plan-v2&envId=top-100-liked
     */
    class Solution {
        public int longestConsecutive(int[] nums) {
            int ans = 0;
            Set<Integer> st = new HashSet<>();
            for (int x : nums) {
                st.add(x);
            }
            for (int x : st) {
                if (st.contains(x - 1)) {
                    continue;
                }
                int y = x + 1;
                while (st.contains(y)) {
                    y++;
                }
                ans = Math.max(ans, y - x);
            }
            return ans;
        }
    }
}
